package com.base.self.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.base.result.ResponseResult;
import com.base.result.ResponseResultUtils;
import com.base.self.entity.MerchantCollectionImage;
import com.base.self.entity.PtintegralRecharge;
import com.base.self.service.IPtintegralRechargeService;
import com.base.utils.Page;
import com.base.utils.StringUtils;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Api(tags = "积分充值相关接口")
public class PtintegralRechargeController {

    @Autowired(required = true)
    private IPtintegralRechargeService ptintegralRechargeService;


    @GetMapping("/admin/ptintegralRecharge")
    @ApiOperation("获取积分充值表单列表")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId",value = "商家id"),
            @ApiImplicitParam(name = "subId",value = "用户id")
    })
    public ModelAndView load(String parentId , Integer currentPageNo,String subId){
        QueryWrapper<PtintegralRecharge> wrapper = new QueryWrapper<PtintegralRecharge>();
        if (StringUtils.isNotEmpty(parentId)) {
            wrapper.eq("parent_id", parentId);
        }
        wrapper.eq("del_flag",0);
        if (StringUtils.isNotEmpty(subId)){
            wrapper.eq("sub_id",subId);
        }
        wrapper.orderByDesc("create_time");
        // 设置分页 获取内容
        com.base.utils.Page page = new Page(); // 实例化分页
        page.setCurrentPageNo(null==currentPageNo?1:currentPageNo); // 设置当前页
        page.setRecordTotal(ptintegralRechargeService.count(wrapper)); // 设置总条数
        PageHelper.startPage(null==currentPageNo?1:currentPageNo,page.getPageSize());
        List<PtintegralRecharge> list = ptintegralRechargeService.list(wrapper);
        ModelAndView modelAndView = new ModelAndView("jsp/index_jifenchongzhishenhe");
        modelAndView.addObject("rows",list);
        modelAndView.addObject("pages", page); // 分页
        return modelAndView;
    }

    @PostMapping("/admin/ptintegralRecharge/audit")
    @ApiOperation("积分充值审核")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "充值id"),
            @ApiImplicitParam(name = "status",value = "审核 1通过 2拒绝"),
            @ApiImplicitParam(name = "remake",value = "审核意见")
    })
    public ResponseResult update(String id,Integer status,String remake){

        ptintegralRechargeService.audit(id,status,remake);
        return ResponseResultUtils.getResponseResultS("审核成功");
    }

    @PostMapping("/ptintegralRecharge/insert")
    @ApiOperation("积分充值表单提交")
    @ResponseBody
    public ResponseResult insert(@Validated PtintegralRecharge ptintegralRecharge){
        ptintegralRechargeService.insert(ptintegralRecharge);
        return ResponseResultUtils.getResponseResultS("提交成功");
    }


    @PostMapping("/admin/ptintegralRecharge/delete")
    @ApiOperation("积分充值表单删除")
    @ResponseBody
    public ResponseResult delete(String id){
        ptintegralRechargeService.removeById(id);
        return ResponseResultUtils.getResponseResultS("删除成功");
    }



}
